import Vue from 'vue'
import VueRouter from 'vue-router'
import ReG from '../views/Reg/Reg.vue'
import LogiN from '../views/Login/Login.vue'
import Main from '../views/Main/Main.vue'
// 导入Home组件
import Home from '../views/menus/Home/Home.vue'
// 导入UserInfo组件
import UserInfo from '../views/menus/User/UserInfo.vue'
// 导入头像组件
import UserAvatar from '../views/menus/User/UserAvatar.vue'
// 导入密码组件
import UserPwd from '../views/menus/User/UserPwd.vue'
// 导入文章分类组件
import ArtCate from '../views/menus/article/ArtCate.vue'
Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
const routes = [
  { path: '/reg', component: ReG },
  { path: '/login', component: LogiN },
  {
    path: '/',
    component: Main,
    // 3. 开启路由重定向
    redirect: '/home',
    children: [
      // 2. home 作为 子路由规则
      { path: 'home', component: Home },
      { path: 'user-Info', component: UserInfo },
      // 声明子组件规则
      { path: 'user-avatar', component: UserAvatar },
      // 重置密码的子组件路由规则
      { path: 'user-pwd', component: UserPwd },
      // 导入文章分类组件
      { path: 'art-cate', component: ArtCate }
    ]
  }
]

const router = new VueRouter({
  routes
})

export default router
